<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>

<s:property value="cityname"/>
<span id="${dvid}_p" style="display:none"></span>
<span id="${dvid}_c" style="display:none"></span>
<span id="${dvid}_a" style="display:none"></span>
<span id="${dvid}_s" style="display:none"></span>
<s:if test="jaddress">
<span id="${dvid}_t"><input id="t_${dvid}_t" type="text"/></span>
</s:if>

<script type="text/javascript">
	function class_acity(dvid){this.a_dvid=dvid;}
	var acity= new class_acity("${dvid}");
	
	class_acity.prototype.load=function(me,cid,sct){
		var dvid=this.a_dvid;
		var thisme=this;
		this.cid=cid;this.sct=sct;
		if(!isnull(me)){
			this.cname=me.options[me.selectedIndex].text;
		}
		
		var fun=function(data){
			var ct=data.ct;
			thisme.subname=data.subname;
			
			if(1==data.s){
			initsp();
			$("#"+dvid+"_p").show();
			
			var cl=data.cl;
				var lselid="";
				
				switch(ct){
				case 0:
					lselid="s_"+dvid+"_p";
					break;
				case 10:
					if(data.count<=0&&ct>0){return;}
					$("#"+dvid+"_c").show();
					lselid="s_"+dvid+"_c";
					break;
				case 20:
					$("#"+dvid+"_c").show();
					if(data.count<=0&&ct>0){return;}
					$("#"+dvid+"_a").show();
					lselid="s_"+dvid+"_a";
					break;
				case 30:
					$("#"+dvid+"_c").show();
					$("#"+dvid+"_a").show();
					if(data.count<=0&&ct>0){return;}
					$("#"+dvid+"_s").show();
					lselid="s_"+dvid+"_s";
					break;
				}
				createSel(dvid,ct);				
				loadsel(lselid,"-1","请选择",true);
				for (var index in cl) {
					loadsel(lselid,index,cl[index],false);
				}
			}else{
				switch(ct){
				case 0:
					initsp();
					$("#"+dvid+"_p").show();
					loadsel("s_"+dvid+"_p","-1","无数据",true);
					break;
				case 10:
					initsp();
					$("#"+dvid+"_c").show();
					loadsel("s_"+dvid+"_c","-1","无数据",true);
					break;
				case 20:
					initsp();
					$("#"+dvid+"_a").show();
					loadsel("s_"+dvid+"_a","-1","无数据",true);
					break;
				case 30:
					initsp();
					$("#"+dvid+"_s").show();
					loadsel("s_"+dvid+"_s","-1","无数据",true);
					break;
				}
			}
		};
		if(cid==-1){
			var tcid="";
			switch(sct){
			case 10:
				$("#"+dvid+"_c").hide();
				break;
			case 20:
				$("#"+dvid+"_a").hide();
				break;
			case 30:
				$("#"+dvid+"_s").hide();
				break;
			}
			return;
		}
		
		if(sct!=0&&sct!=10&&sct!=20){
			return;
		}
		
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}cityutil${aier_suffix}"), fun, {"cityid" :cid});
		
		function initsp(){
		    $("#"+dvid+"_p").hide();$("#"+dvid+"_c").hide();$("#"+dvid+"_a").hide();$("#"+dvid+"_s").hide();
      	}
      	
      	function loadsel(id,v,c,init){
      		if(init){$("#"+id).html("");}
      		$("#"+id).append('<option value="'+v+'">'+c+'</option>'); 
      	}
      	
      	function createSel(id,ct){
      		var sid="";
      		var selid="";
      		switch(ct){
      		case 0:sid=id+"_p";selid="s_"+id+"_p";break;
      		case 10:sid=id+"_c";selid="s_"+id+"_c";break;
      		case 20:sid=id+"_a";selid="s_"+id+"_a";break;
      		case 30:sid=id+"_s";selid="s_"+id+"_s";break;
      		}
      		$("#"+sid).html("<select id='"+selid+"' onchange='load(this,"+ct+")'></select>");
      	}
	};
	function load(me,ct){
		acity.load(me,me.value,ct);
	}
	acity.load(null,<s:property value="cityid"/>,<s:property value="ct"/>);
		
</script>
